
#include "message.hpp"

#include <thread>
#include "net.hpp"

void onMessage(const gmrpc::BaseConnection::ptr &conn, gmrpc::BaseMessage::ptr &msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;
}

int main()
{
    auto client = gmrpc::ClientFactory::create("127.0.0.1", 9090);
    client->setMessageCallback(onMessage);
    client->connect();

    auto rpc_req = gmrpc::MessageFactory::create<gmrpc::RpcRequest>();
    rpc_req->setId("11111");
    rpc_req->setMType(gmrpc::MType::REQ_RPC);
    rpc_req->setMethod("Add");
    Json::Value param;
    param["num1"] = 11;
    param["num2"] = 22;
    rpc_req->setParams(param);
    std::cout <<"-----------------------"<<std::endl;
    client->send(rpc_req);
    std::cout <<"-----------------------"<<std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(10));
    client->shutdown();
    return 0;
}